package com.copm.ifm.servers.sys.controller;

import com.copm.ifm.base.basic.ServiceResponse;
import com.copm.ifm.base.service.base.BaseController;
import com.copm.ifm.servers.sys.entity.SysFile;
import com.copm.ifm.servers.sys.service.SysFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


/**
 * <p>
 * 文件传输类
 * </p>
 *
 * @author tp
 * @since 2021-1-19
 */
@Slf4j
@Api(tags = "文件上传下载/sys-file")
@RestController
@RequestMapping("/sys-file")
@CrossOrigin(origins = "*", maxAge = 3600)
public class FileController extends BaseController {

    @Autowired
    SysFileService sysFileService;

    @PostMapping("/import")
    @ApiOperation("文件上传")
    public ServiceResponse<SysFile> uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
        return success(sysFileService.uploadFile(file));
    }

    @GetMapping("/export")
    @ApiOperation("文件下载")
    public ServiceResponse<SysFile> exportFile(@RequestBody SysFile sysFile) throws IOException {
        return success(sysFileService.exportFile(sysFile));
    }

}
